package com.briup.smartcity_group6.web.controller;


import com.briup.smartcity_group6.bean.basic.Article;
import com.briup.smartcity_group6.service.IArticleService;
import com.briup.smartcity_group6.utils.Result;
import com.briup.smartcity_group6.utils.ResultUtil;
import com.briup.smartcity_group6.web.vo.ArticleVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/auth/article")
@Api(tags = "咨询信息模块")
@RestController
public class ArticleController {
    @Autowired
    private IArticleService service;
    @ApiOperation("通过id删除咨询信息")
    @ApiImplicitParam(name = "id", value = "咨询信息的id", type = "int", required = true)
    @DeleteMapping()
    public Result deleteById(Integer id) {
        service.deleById(id);
        return ResultUtil.success("操作成功");

    }

    @ApiOperation("更新或者修改信息")
    @PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public Result saveOrUpdate(Article article) {
        service.saveOrUpdate(article);
        return ResultUtil.success("操作成功");
    }
    @ApiOperation("根据id修改咨询状态")
    @PostMapping(value = "/status",consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public Result changeStatusById(Integer id,Integer status){
        service.changeStatus(id,status);
        return ResultUtil.success("审核成功");
    }
    @ApiOperation("根据id查询咨询信息")
    @ApiImplicitParam(name = "id",value = "咨询信息编号",required = true)
    @GetMapping()
    public Result findByIdWithCategoryAndUser(Integer id){
        ArticleVO articleVO = service.findByIdWithCategoryAndUser(id);
        return ResultUtil.success(articleVO);
    }
    @ApiOperation("分页查询咨所有询信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "title",value = "标题",required = false),
            @ApiImplicitParam(name = "categoryId",value = "栏目id",required = false),
            @ApiImplicitParam(name = "status",value = "咨询状态",required = false),
            @ApiImplicitParam(name = "pageNum",value = "当前页码",required = true),
            @ApiImplicitParam(name = "pageSize",value = "页的大小",required = true)
    })
    @GetMapping("/categoryAndUser")
    public Result findByPage(int pageNum, int
            pageSize, String title, Integer status, Integer categoryId){
        PageInfo<ArticleVO> pageInfo=service.pageQueryArticleWithCategoryAndUser(pageNum,pageSize,title,status,categoryId);
        return ResultUtil.success(pageInfo);
    }

    @ApiOperation("分页查询推荐信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "起始页", required = true),
            @ApiImplicitParam(name = "pageSize", value = "页大小", required = true)
    })
    @GetMapping("/page/query/recommend")
    public Result  recommend(int pageNum, int pageSize){
        PageInfo<ArticleVO> pageInfo = service.pageQueryRecommend(pageNum, pageSize);
        return ResultUtil.success(pageInfo);
    }
}
